package lu.med.praxiswahl.wahlumed.service.beans;

import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Remote;
import javax.ejb.Stateless;

import lu.med.praxiswahl.wahlumed.dao.beans.daointerface.OPBillContentsDAOInt;
import lu.med.praxiswahl.wahlumed.model.beans.OPBillContentsTBL;
import lu.med.praxiswahl.wahlumed.service.beans.serviceinterface.OPBillContentServiceInt;

/**
 * Session Bean implementation class OPBillContentService
 */
@Stateless
@Remote({ OPBillContentServiceInt.class })
public class OPBillContentService implements OPBillContentServiceInt {

	@EJB
	private OPBillContentsDAOInt opBillContentDao;

	/**
	 * Default constructor.
	 */
	public OPBillContentService() {
	}

	@Override
	public int createBillContents(OPBillContentsTBL contentItem)
			throws RuntimeException {
		opBillContentDao.persist(contentItem);
		return DONE;
	}

	@Override
	public List<OPBillContentsTBL> getBillsContentItemsByOPBillNumber(
			Long opBillNumber) {
		List<OPBillContentsTBL> resultList = opBillContentDao
				.findBillsContentByBillNumber(opBillNumber);

		return resultList;
	}

	@Override
	public int removeOPBillContentItem(Long id) throws RuntimeException {
		opBillContentDao.delete(id);
		return DONE;
	}

	@Override
	public void updateOPBillContents(OPBillContentsTBL contentItem)
			throws RuntimeException {

		OPBillContentsTBL itemClone = this.opBillContentDao
				.findBillsContentByID(contentItem.getOpbillsContentsID());

		itemClone.setCode_rate(contentItem.getCode_rate());
		itemClone.setDate_dent_heure(contentItem.getDate_dent_heure());
		itemClone.setH(contentItem.getH());
		itemClone.setMed(contentItem.getMed());
		itemClone.setMed_pres(contentItem.getMed_pres());
		itemClone.setMontant(contentItem.getMontant());
		itemClone.setAnzahl(contentItem.getAnzahl());
		itemClone.setRechnungs_nummer(contentItem.getRechnungs_nummer());
		itemClone.setSettlement_code(contentItem.getSettlement_code());

		this.opBillContentDao.update(itemClone);

	}

}
